package com.java.comprehensive.arithmetic.leecode.tags.array;

import java.util.Arrays;

/**
 * @program: comprehensive-service
 *
 * @description: 移动零
 *
 * @author: 窦绍飞
 *
 * @create: 2021-12-13 11:03
 **/
public class LeetCode_283 {

	public static void moveZeroes(int[] nums) {
		int right = nums.length - 1;
		int left = 0;

		while (left <= right) {
			if (nums[left] == 0) {
				while (nums[right] == 0 && left < right) {
					right--;
				}

				for (int i = left + 1; i <= right; i++) {
					int temp = nums[i];
					nums[i - 1] = temp;
				}
				nums[right] = 0;
				right--;
			} else {
				left++;
			}

		}

	}

	public static void moveZeroesTwo(int[] nums) {
		int point = 0;
		for (int i = 0; i < nums.length; i++) {
			if (nums[i] != 0) {
				nums[point] = nums[i];
				point += 1;
			}
		}
		for (int i = point; i < nums.length; i++) {
			nums[i] = 0;
		}
	}

	public static void main(String[] args) {
		int[] nums = { 0, 0, 1 };
		moveZeroes(nums);
		System.out.println(Arrays.toString(nums));
	}
}
